package com.example.components.controller;

import com.example.components.entity.Result;
import com.example.components.exception.BaseAppException;
import com.example.components.model.AlarmRuleDo;
import com.example.components.service.AlarmRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * @Auther: Jason
 * @Date: 2022/4/9 21:12
 * @Description:
 */
@Api(tags = "告警规则")
@RestController
@RequestMapping("/alarm")
public class AlarmRuleController {

    @Autowired
    private AlarmRuleService alarmService;

    @ApiOperation("根据资源类型查询告警规则列表")
    @GetMapping("/getAlarmRuleList")
    public Result<List<AlarmRuleDo>> queryAlarmRuleList(@ApiParam(value = "资源类型", required = true)@RequestParam Integer resourceType) throws BaseAppException {
        Assert.notNull(resourceType, "resourceType cannot be null");
        return Result.ofSuccess(alarmService.queryAlarmRuleList(resourceType));
    }

    @ApiOperation("刷新告警规则")
    @GetMapping("/syncAlarmRule")
    public void syncAlarmRule(@ApiParam(value = "资源类型", required = true)@RequestParam Integer resourceType) throws BaseAppException {
         alarmService.syncAlarmRule(resourceType);
    }


}
